package com.rpc.example.serial;

import com.alibaba.fastjson.JSON;
import com.rpc.example.constant.SerializeTypeEnum;
/**
 *  
 *  
 * @author Elvis
 * @version 1.0, 2022/11/10
 */
public class JsonSerialize implements ISerial {
    @Override
    public <T> byte[] serialized(T message) {
        String s = JSON.toJSONString(message);
        return s.getBytes();
    }

    @Override
    public <T> T deserialize(byte[] bytes, Class<T> clazz) {
        T t = JSON.parseObject(new String(bytes), clazz);
        return t;
    }

    @Override
    public byte getSerializeType() {
        return SerializeTypeEnum.JSON.getCode();
    }
}
